import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.security.NoSuchAlgorithmException;

import map.MappingService;

import client.UDPClient;

import server.UDPServer;
import service.CreateFileService;
import utility.CONST;
import utility.FileService;
import data.FindFilePacket;
import data.GetFilePacket;
import data.Packet;
import data.ResponseFindFilePacket;

public class Main {
	
	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException {
		
		/*UDPServer server = new UDPServer();
		UDPClient client = new UDPClient("D:\\abc.torrent");
		
		DatagramSocket clientSocket = null;
		clientSocket = new DatagramSocket();
		DatagramPacket sendFindFilePacket = null;
		DatagramPacket sendGetFilePacket = null;
		InetAddress ip = InetAddress.getByName("127.0.0.1");
		
		FileService utility = new FileService();
		
		Packet findFilePacket = new FindFilePacket("Chude1-StoreProcedure-Trigger-Function.pdf.part1.chunk", "23b73a3823cbd7a0e2c8581490b58fe02142c128");
		
		byte[] findFilePacketByteArr = utility.objToByte(findFilePacket);
		
		sendFindFilePacket = new DatagramPacket(findFilePacketByteArr, findFilePacketByteArr.length, ip, CONST.DEFAULT_PORT);
		
		clientSocket.send(sendFindFilePacket);
		
		clientSocket.receive(sendFindFilePacket);
		
		byte[] b = sendFindFilePacket.getData();
		
		Packet p1 = (Packet) utility.byteArrayToObj(b);
		ResponseFindFilePacket responseFindFile = (ResponseFindFilePacket) p1;
		
		Packet getFilePacket = new GetFilePacket(responseFindFile.getFilePath());
		
		byte[] getFilePacketByteArr = utility.objToByte(getFilePacket);
		sendGetFilePacket = new DatagramPacket(getFilePacketByteArr, getFilePacketByteArr.length, CONST.DEFAULT_PORT);*/
		
		FileService utility = new FileService();
		
		//utility.readTorrentFileIntoApp("D:\\abc.torrent");
		utility.createMapping("D:\\torrent\\node.map", MappingService.listVertex, MappingService.listEdge);
		boolean kq = utility.KruskalAlg(MappingService.listEdge, MappingService.listVertex, MappingService.tree);
		//Main.getChunk();
	}
	
	public static void getChunk() {
		String filePath = "Chude1-StoreProcedure-Trigger-Function.pdf";
		String chunkPath = "D:\\torrent\\";
		String torrentPath = "D:\\abc.torrent";
		CreateFileService fileService = new CreateFileService(filePath, chunkPath, torrentPath);
		
		Thread t = new Thread(fileService);
		t.start();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see java.lang.Object#Object()
	 */
	public Main() {
		super();
	}

}